<?php

//函数引用指针
function build_row(&$text){
    $text = "<tr><td>$text</td></tr>";
} 
echo '<table border="1">'; 
$t = '测试数据'; 
build_row($t); 
echo $t;echo $t;echo $t;
echo '</table>';

//变量使用指针
$a = 123;
$b = &$a;
$b = 456;
echo $a;

//怎么查看一个变量的占用内存
echo memory_get_usage() , '<br>';  
$start = memory_get_usage();  
$a = [];  
for ($i=0; $i<1000; $i++) {  
$a[$i] = $i + $i;  
}  
$mid =  memory_get_usage();  
echo memory_get_usage() , '<br>';  
for ($i=1000; $i<2000; $i++) {  
$a[$i] = $i + $i;  
}  
$end =  memory_get_usage();  
echo memory_get_usage() , '<br>';  
echo 'argv:', ($mid - $start)/1000 ,'bytes' , '<br>';  
echo 'argv:',($end - $mid)/1000 ,'bytes' , '<br>';  

//使用内置函数生成的数组更接近真实的空间
$start = memory_get_usage();  
$a = array_fill(0, 10000, 1);  
$mid = memory_get_usage(); //10k elements array;  
echo 'argv:', ($mid - $start )/10000,'byte' , '<br>';  
$b = array_fill(0, 10000, 1);  
$end = memory_get_usage(); //10k elements array;  
echo 'argv:', ($end - $mid)/10000 ,'byte' , '<br>';  
